package com.cg.design.graphicdesignpattern.abstractfactory.factory;

/**
 * 抽象的工厂类：Factory类
 *
 * @program: LeetCode->Factory
 * @description: 抽象的工厂类：Factory类
 * @author: cg
 * @create: 2022-03-21 20:54
 **/
public abstract class Factory {

    /**
     * 通过反射动态地读取类信息，生成的使具体工厂的实例，但返回的类型使抽象工厂类型（Factory）
     * @param className
     * @return
     */
    public static Factory getFactory(String className) {
        Factory factory = null;
        try {
            factory = (Factory) Class.forName(className).newInstance();
        } catch (ClassNotFoundException e) {
            System.err.println(" 没有找到 " + className + " 类 ");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return factory;
    }

    public abstract Link createLink(String caption, String url);

    public abstract Tray createTray(String caption);

    public abstract Page createPage (String title, String author);

}
